<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Graphql</title>
</head>
<body>
  <h1>GraphQL Demo</h1>
  <button onclick="getData()">获取数据</button>
  <script>
  function getData() {
    const query = `
    query Account($username: String, $city: String) {
      account(username: $username) {
        age
        sex
        salary(city: $city)
      }
    }
    `
    const variables = { username: '李大四', city: '深圳'};
    fetch('/graphql', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
      },
      body: JSON.stringify({
        query: query,
        variables: variables
      })
    }).then(res => res.json())
    .then(data => {
      console.log(data);
    })
  }
  </script>
</body>
</html>